package com.swing.demo;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;

public class SwingDemo {
    public static void main(String[] args) {
        System.out.println("test");
        containerDemo();
    }
    /**
     * 三个顶层容器类：JFrame，JDialog和JApplet。当使用这些容器类时，请谨记以下原则。
     * */
    public static void containerDemo() {
    	//构造函数title参数
    	JFrame frame = new JFrame("this is a frame window");
    	frame.setBounds(100,100,800,400);
    	frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
    	frame.setVisible(true);  
    	JButton jbtn = new JButton("show button");
    	jbtn.setBounds(10, 30, 100, 20);	//设置按钮的大小
    	jbtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				System.out.print("show dialog");
		    	createConfirmDialog(frame,true);

				
			}
		});
    	Container fmContainer= frame.getContentPane();
    	fmContainer.add(jbtn);
    	//JDialog:
//    	JDialog dialog = new JDialog();
    	//JDialog(Dialog owner, boolean modal)
    	//JDialog(Dialog owner, boolean modal)
    	//JDialog(Dialog owner, String title)
    	//JDialog(Frame owner, String title, boolean modal):创建一个具有指定标题的对话框，所有者为 Frame和模态。
    	//JDialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)
    }
    
    public static void createConfirmDialog(JFrame frame,Boolean visible) {
    	JDialog dialog= new JDialog(frame,"dialog window container",true);
    	Container container = dialog.getContentPane();
    	container.add(new JLabel("this is a label"));
    	dialog.setBounds(100, 100, 200, 100);
    	dialog.setVisible(visible);
	}
    
    
}